package com.bawei.module_live.ui.adapter

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_live.R

class GiftCountAdapter(
    private val countOptions: List<Int>,
    private val onCountSelected: (Int) -> Unit
) : RecyclerView.Adapter<GiftCountAdapter.CountViewHolder>() {

    inner class CountViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val countText: TextView = itemView.findViewById(R.id.count_text)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CountViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_gift_count, parent, false)
        return CountViewHolder(view)
    }

    override fun onBindViewHolder(holder: CountViewHolder, position: Int) {
        Log.d("GiftAdapter", "bind pos=$position, title=${countOptions[position]}")
        val count = countOptions[position]
        holder.countText.text = count.toString()
        
        holder.itemView.setOnClickListener {
            onCountSelected(count)
        }
    }

    override fun getItemCount(): Int = countOptions.size
} 